package com.shop.cereshop.business.service.shop.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.cereshop.business.dao.shop.CereShopSkuDAO;
import com.shop.cereshop.business.service.shop.CereShopSkuService;
import com.shop.cereshop.commons.domain.shop.CereShopSku;
import com.shop.cereshop.commons.domain.shop.CereShopSkuName;
import com.shop.cereshop.commons.domain.shop.bo.CereShopSkuBo;
import com.shop.cereshop.commons.domain.shop.vo.CereShopSkuNameVo;
import com.shop.cereshop.commons.domain.shop.vo.CereShopSkuVo;
import org.assertj.core.util.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CereShopSkuServiceImpl extends ServiceImpl<CereShopSkuDAO, CereShopSku> implements CereShopSkuService {

    @Override
    public List<CereShopSkuVo> queryList(CereShopSkuBo bo) {
        List<CereShopSku> list = list(build(bo));
        if (CollectionUtil.isNotEmpty(list)){
            return convert(list);
        }
        return null;
    }

    @Override
    public LambdaQueryWrapper<CereShopSku> build(CereShopSkuBo bo) {
        LambdaQueryWrapper<CereShopSku> q1 = new LambdaQueryWrapper<>();
        q1.eq(ObjectUtil.isNotNull(bo.getShopId()),CereShopSku::getShopId,bo.getShopId());
        q1.eq(ObjectUtil.isNotNull(bo.getSkuName()),CereShopSku::getSkuName,bo.getSkuName());
        return q1;
    }

    @Override
    public CereShopSkuVo convert(CereShopSku cereShopSku) {
        CereShopSkuVo vo = new CereShopSkuVo();
        BeanUtils.copyProperties(cereShopSku,vo);
        return vo;
    }

    @Override
    public List<CereShopSkuVo> convert(List<CereShopSku> cereShopSkuList) {
        List<CereShopSkuVo> vos = Lists.newArrayList();
        for (CereShopSku cereShopSku : cereShopSkuList) {
            vos.add(convert(cereShopSku));
        }
        return vos;
    }
}
